package cn.wolfcode.wolf2w.web.controller;

import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.query.BannerQuery;
import cn.wolfcode.wolf2w.service.IBannerService;
import cn.wolfcode.wolf2w.uitl.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
@RequestMapping("banner")
public class BannerController {
    @Autowired
    private IBannerService bannerService;
    @RequestMapping("/getAllType")
    @ResponseBody
    public Object getAllType(){
        return JsonResult.success(bannerService.getAllTypeMap());

    }
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") BannerQuery qo){
        Page<Banner> page =bannerService.query(qo);
        model.addAttribute("page",page);
        //直接返回页面
        return "banner/list";
    }
    /**
     * 通过区域id删除数据
     * @par
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        bannerService.delete(id);
        return JsonResult.success();
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOUpdate(Banner banner ){
        //添加或者修改都把目的地名字带上
        bannerService.saveOrUpdate(banner);
        return JsonResult.success();
    }
    
}
